﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Scripting.Actions;
using Microsoft.Scripting.Ast;
using Microsoft.Scripting.Generation;
using Microsoft.Scripting.Runtime;
using Microsoft.Scripting.Actions.Calls;

namespace DlrBasic.Runtime
{
    /// <summary>
    /// Basic almost default binder. Does not do much.
    /// </summary>
    class DlrBasicBinder : DefaultBinder 
    {
        public DlrBasicBinder(ScriptDomainManager manager)
            : base(manager)
        {
        }

        protected override RuleBuilder<T> MakeRule<T>(OldDynamicAction action, object[] args)
        {
            return base.MakeRule<T>(action, args);
        }


        public override bool CanConvertFrom(Type fromType, Type toType, bool toNotNullable, NarrowingLevel level)
        {
            return toType.IsAssignableFrom(fromType);
        }

        public override Candidate PreferConvert(Type t1, Type t2)
        {
            throw new NotImplementedException();
        }

        public override object Convert(object obj, Type toType)
        {
            if (toType == typeof(String))
                return obj == null ? String.Empty : toType.ToString();
            else
            {
                return global::System.Convert.ChangeType(obj, toType);
            }
        }
    }
}
